<template>
	<div class="container">
		<!-- 头部标题栏 -->
		<h3 class="header-title clearfix">
			<span></span>
			<p>{{$store.getters.getPageTitle}}</p>
		</h3>
		<!-- 搜索栏 -->
		<comSearch :options="search" @searchList="searchData"></comSearch>
		<!-- 新增资料 -->
		<matMgAddMsg ref="material" :options="material" @addMaterial="addMaterial"></matMgAddMsg>
		<!-- 数据列表 -->
		<comTable :options="tableData" @openDetailsDialog="function(data){return openDetailsDialog('明细',data)}"
			class="addTab" @openRemarksDialog="function(data){return openDetailsDialog('备注',data)}"
			@addRemarks="addRemarks" @openResume="openResume" @openUpload="openUpload" @recovery="recovery"
			@openModifyArrange="function(data){return openModifyDialog(data,'arrange')}"
			@openModifyName="function(data){return openModifyDialog(data,'name')}"
			@openModifyTelnum="function(data){return openModifyDialog(data,'telnum')}"
			@openModifySex="function(data){return openModifyDialog(data,'sex')}"
			@openModifyAge="function(data){return openModifyDialog(data,'age')}"
			@openModifyEducation="function(data){return openModifyDialog(data,'education')}"
			@openModifyNativePlace="function(data){return openModifyDialog(data,'nativePlace')}"
			@openModifyPresentAddress="function(data){return openModifyDialog(data,'presentAddress')}"
			@openModifyPosition="function(data){return openModifyDialog(data,'position')}"
			@openModifyWorkStatus="function(data){return openModifyDialog(data,'workStatus')}"
			@openModifyProjectBelongs="function(data){return openModifyDialog(data,'projectBelongs')}"
			@openModifyrecruitmentChannel="function(data){return openModifyDialog(data,'recruitmentChannel')}"
			@openModifyProjectHiredate="function(data){return openModifyDialog(data,'hiredate')}"
			@editeInterviewTime="function(data){return openModifyDialog(data,'interviewTime')}"
			@openModifyregion="function(data){return openModifyDialog(data,'region')}"
			@openModifyNativecardNum="function(data){return openModifyDialog(data,'cardNum')}"
			@openModifytradeName="function(data){return openModifyDialog(data,'tradeName')}"
			@openModifyjobName="function(data){return openModifyDialog(data,'jobName')}"
			@openModifysalaryExpectation="function(data){return openModifyDialog(data,'salaryExpectation')}"
			@openModifyoriginalCompany="function(data){return openModifyDialog(data,'originalCompany')}"
			@openModifyoriginalCity="function(data){return openModifyDialog(data,'originalCity')}"
			@openModifyannualSalary="function(data){return openModifyDialog(data,'annualSalary')}"
			></comTable>
		<!-- 修改明细弹窗 -->
		<comDetails :options="detailsData" @getDetailsList="getDetailsList"></comDetails>
		<!-- 新增备注弹窗 -->
		<perMgAddRemarks ref="remark" :options="remarksData" @subRemarks="subRemarks"></perMgAddRemarks>
		<!-- 简历模板弹窗 -->
		<comResume :options="remuseData"></comResume>
		<!-- 上传简历弹窗 -->
		<matMgUploadResume :options="uploadData" @updateView="updateView"></matMgUploadResume>
		<!-- 修改资料弹窗 -->
		<matMgUpdateData :options="updateData" @updateData="modifyData"></matMgUpdateData>
		<!-- 分页器 -->
		<div class="pageBox">
			<el-pagination @size-change="handleSizeChange" @current-change="pageChange" :current-page="cur"
				:page-sizes="[10, 20, 30, 50, 100]" :page-size="pageSize"
				layout="total, sizes, prev, pager, next, jumper" :total="totalNum" background></el-pagination>
		</div>
	</div>
</template>

<script>
	export default {
		components: {
			comSearch: () => import("../commonComponents/comSearch.vue"),
			matMgAddMsg: () => import("../pageComponents/matMgAddMsg.vue"),
			comTable: () => import("../commonComponents/comTable.vue"),
			comResume: () => import("../commonComponents/comResume.vue"),
			comDetails: () => import("../commonComponents/comDetails.vue"),
			perMgAddRemarks: () => import("../pageComponents/perMgAddRemarks.vue"),
			matMgUploadResume: () => import("../pageComponents/matMgUploadResume.vue"),
			matMgUpdateData: () => import("../pageComponents/matMgUpdateData.vue"),
		},
		data() {
			return {
				/* 搜索列表 */
				search: {
					userShow: true, //姓名
					telShow: true, //电话号码
					// tagShow: true,												//标注
					sexShow: true, //性别
					// ageShow: true,												//年龄
					// educationShow: true,										//学历
					// addressShow: true,											//现住址
					workStatusShow: true, //工作状态
					postShow: true, //岗位
					projectShow: true, //项目归属
					startOperationTimeShow: true,
					tradeName:true,
					region:true,
					jobName:true,
					
					// entryShow: true,											//录入时间
					data: {}, //查询数据
				},
				/* 录入资料数据 */
				material: {

				},
				/* 列表数据 */
				tableData: {
					list: [
						// {title: '标注',prop: 'arrange',isClick: true,eventName: 'openModifyArrange'},
						{
							title: '姓名',
							prop: 'name',
							isClick: true,
							eventName: 'openModifyName'
						},
						{
							title: '手机号',
							prop: 'telnum',
							isClick: true,
							eventName: 'openModifyTelnum'
						},
						{
							title: '性别',
							prop: 'sex',
							isClick: true,
							eventName: 'openModifySex'
						},
						{title: '年龄',prop: 'age',isClick: true,eventName: 'openModifyAge'},
						{title: '居住地',prop: 'region',isClick: true,eventName: 'openModifyregion'},
						{title: '身份证号码',prop: 'cardNum',isClick: true,eventName: 'openModifyNativecardNum'},
						{title: '职能',prop: 'tradeName',isClick: true,eventName: 'openModifytradeName'},
						{title: '职位名称',prop: 'jobName',isClick: true,eventName: 'openModifyjobName'},
						{title: '期望薪资',prop: 'salaryExpectation',isClick: true,eventName: 'openModifysalaryExpectation'},
						{title: '原工作单位',prop: 'originalCompany',isClick: true,eventName: 'openModifyoriginalCompany'},
						{title: '原工作城市',prop: 'originalCity',isClick: true,eventName: 'openModifyoriginalCity'},
						{title: '原年薪',prop: 'annualSalary',isClick: true,eventName: 'openModifyannualSalary'},
						{
							title: '状态',
							prop: 'workStatus',
							isClick: true,
							eventName: 'openModifyWorkStatus'
						},
						{
							title: '项目归属',
							prop: 'projectBelongs',
							isClick: true,
							eventName: 'openModifyProjectBelongs'
						},

						{
							title: '招聘渠道',
							prop: 'recruitmentChannel',
							isClick: true,
							eventName: 'openModifyrecruitmentChannel'
						},
						{
							title: '操作时间',
							prop: 'updateTime',
							isClick: true,
							eventName: 'openModifyProjectHiredate'
						},
						{
							title: '面试时间',
							prop: 'interviewTime',
							isClick: true,
							eventName: 'editeInterviewTime'
						},
						{
							title: '最新备注',
							prop: 'projectRemark',
							isClick: true,
							eventName: 'addRemarks'
						},
						// {title: '历史备注',prop: 'oldRemarks',isClick: false},
						// {title: '录入时间',prop: 'createTime',isClick: false},
					],
					noResume: true, //简历
					resumeList: [{
							name: '查看简历',
							isBtn: false,
							title: 'openResume'
						},
						{
							name: '上传简历',
							isBtn: false,
							title: 'openUpload'
						},
					],
					noOperation: true, //有操作项
					operation: [ //操作项内容
						{
							name: '修改明细查看',
							isBtn: false,
							title: 'openDetailsDialog'
						},
						{
							name: '所有备注查看',
							isBtn: false,
							title: 'openRemarksDialog'
						},
						// {
						// 	name: '放入回收站',
						// 	isBtn: false,
						// 	title: 'recovery'
						// },
					],
					data: [
						/* {
							arrange: '已安排',
							name: '徐凤年',
							telnum: '156565656',
							position: '月嫂',
							workStatus: '在职',
							projectBelongs: '发财网络科技有限公司',
							newRemarks: 'xxx',
							oldRemarks: 'xxx',
							createTime: '2020-1-55',
							resume: '查看简历'
						}, */
					]
				},
				/* 明细弹窗数据 */
				detailsData: {
					showDialog: false, //显示弹窗
					title: '修改明细', //标题
					list: [ //数据列表
						/* {	
							title: '2020年09月11日10:41:54',						//标题
							content: '修改手机号码：15202120781 为 手机号码：120383774748',	//内容
						}, */
					]
				},
				/* 添加备注弹窗 */
				remarksData: {
					showDialog: false, //显示弹窗
					title: '添加备注', //标题
				},
				/* 简历模板数据 */
				remuseData: {
					showDialog: false, //显示弹窗
					title: '简历列表', //标题
					list: [
						/* {
							title: '一、简历',
						} */
					],
					userInfo: {}, //当前被操作人员信息
				},
				projectId: '',
				/* 上传简历数据 */
				uploadData: {
					showDialog: false, //显示弹窗
					title: '上传简历', //标题
					fileList: [], //上传简历列表
				},
				/* 修改资料数据 */
				updateData: {
					showDialog: false, //显示弹窗
					title: '修改资料信息', //标题
					type: '', //修改类型
					userInfo: {}, //当前被操作人员信息
					recruitmentChannelList: []
				},


				/* 分页功能数据 */
				cur: 1,
				pageSize: 10,
				totalNum: 0, //总共有多少条数据,根据这个数据去适配页数
			}
		},
		created() {
			this.init();
		},
		methods: {
			//初始化
			init() {
				localStorage.setItem('pageTitle', '招聘信息录入');
				this.$store.dispatch('setPageTitle', localStorage.getItem('pageTitle'));
				this.getDataList();
			},
			//条件搜索
			searchData(data) {
				console.log(data);
				this.search.data = data;
				this.getDataList(data);
			},


			//获取数据列表
			getDataList(form) {
				let params = {
					userId: localStorage.getItem('userid'),
					pageNum: this.cur,
					pageSize: this.pageSize
				}
				if (form) {
					params = Object.assign(params, form)
				};
				this.$telAxios.post('/v1/librarian/selectLibrarianList', params).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						let result = res.data.data;
						this.totalNum = Number(result.totalNum);

						result.llist.forEach(item => {
							item.resume = '查看简历';
							// 状态(1:沟通;2:通知面试；3:实到面试;通知复试:4;实到复试:5;录取:6;到岗:7)
							if (item.workStatus == 1) {
								item.workStatus = '沟通'
							} else if (item.workStatus == 2) {
								item.workStatus = '通知面试'
							} else if (item.workStatus == 3) {
								item.workStatus = '实到面试'
							} else if (item.workStatus == 4) {
								item.workStatus = '通知复试'
							} else if (item.workStatus == 5) {
								item.workStatus = '实到复试'
							} else if (item.workStatus == 6) {
								item.workStatus = '录取'
							} else if (item.workStatus == 7) {
								item.workStatus = '到岗'
							}
							if (item.plist.length > 0) {
								item.projectRemark = item.plist[0].comment
							}
							if (item.plist.length == 0) {
								item.newRemarks = '-';
							} else if (item.plist.length == 1) {
								item.newRemarks = item.plist[0].comment;
							} else if (item.plist.length >= 2) {
								item.newRemarks = item.plist[0].comment;
								item.oldRemarks = item.plist[1].comment;
							}
						});

						this.tableData.data = result.llist;
						this.tableData.data.forEach(item => {
							// if(item.rlist.length>0){
							// 	 item.rlist.forEach(data=>{
							// 		 item.recruitmentChannel+=data+'\n'
							// 	 })	
							// 	item.recruitmentChannel= item.recruitmentChannel.substring(9)
							// }
						})
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
			},
			//新增资料
			addMaterial(form) {
				console.log(form);
				let params = {
					userId: localStorage.getItem('userid'),
					userName: localStorage.getItem('checkHuman')
				}
				if (form) {
					params = Object.assign(params, form)
				};
				console.log(params);
				// params.projectBelongs=
				this.$telAxios.post('/v1/librarian/inserLibrarian', params).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						this.$message({
							message: '录入成功！',
							type: 'success'
						})
						this.$refs.material.clearData();
						this.getDataList();
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
			},
			//打开修改数据弹窗
			openModifyDialog(data, type) {
				console.log(data);
				console.log(type);
				this.updateData.showDialog = true;
				this.updateData.type = type;
				this.updateData.userInfo = data;
				let projectId = '';
				this.$telAxios.get('/v1/librarian/projectBelongsList', {}).then(item => {
					let dat = item.data.data
					dat.forEach(r => {
						if (r.projectBlongs == data.projectBelongs) {
							this.projectId = r.projectId
							console.log(r.projectId);
						}
					})
					this.$telAxios.get('/v1/librarian/pecruitmentChannelByProjectId?projectId=' + this
						.projectId, {}).then(res => {
						this.updateData.recruitmentChannelList = res.data.data
						console.log(res);
					})
				})



			},
			//更新数据
			modifyData(data) {
				console.log(data);
				this.updateData.showDialog = false;
				let params = {
					librarianId: this.updateData.userInfo.librarianId,
					changedFront: this.updateData.userInfo[this.updateData.type],
					changedQueen: data,
					userId:localStorage.getItem('userid'),
					userName:localStorage.getItem('checkHuman'),
					projectId:this.projectId,
				}
				this.updateData.type == 'name' ? params.grade = 1 : '';
				this.updateData.type == 'telnum' ? params.grade = 2 : '';
				this.updateData.type == 'position' ? params.grade = 3 : '';
				this.updateData.type == 'workStatus' ? params.grade = 4 : '';
				this.updateData.type == 'projectBelongs' ? params.grade = 5 : '';
				this.updateData.type == 'arrange' ? params.grade = 6 : '';
				this.updateData.type == 'sex' ? params.grade = 10 : '';
				this.updateData.type == 'age' ? params.grade = 11 : '';
				this.updateData.type == 'education' ? params.grade = 12 : '';
				this.updateData.type == 'nativePlace' ? params.grade = 13 : '';
				this.updateData.type == 'region' ? params.grade = 18 : '';
				// this.updateData.type == 'hiredate' ? params.grade = 16 : '';
				this.updateData.type == 'recruitmentChannel' ? params.grade = 17 : '';
				this.updateData.type == 'interviewTime' ? params.grade = 16 : '';
				this.updateData.type == 'cardNum' ? params.grade = 19 : '';
				this.updateData.type == 'tradeName' ? params.grade = 20 : '';
				this.updateData.type == 'jobName' ? params.grade = 21 : '';
				this.updateData.type == 'salaryExpectation' ? params.grade = 22 : '';
				this.updateData.type == 'originalCompany' ? params.grade = 23 : '';
				this.updateData.type == 'originalCity' ? params.grade = 24 : '';
				this.updateData.type == 'annualSalary' ? params.grade = 25 : '';
				// this.updateData.type == 'hoppingIntention' ? params.grade = 19 : '';
				

				this.$telAxios.post('/v1/librarian/insertDetail', params).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						if (this.updateData.type == 'projectBelongs') {
							params.changedFront = this.updateData.userInfo['recruitmentChannel']
							params.grade = 17
							params.changedQueen = ''
							this.$telAxios.post('/v1/librarian/insertDetail', params).then(res => {})
						}
						this.$message({
							message: '修改成功！',
							type: 'success'
						})
						this.searchData(this.search.data);
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})




			},
			//打开新增备注模板
			addRemarks(data) {
				console.log(data);
				this.remarksData.showDialog = true;
				this.remarksData.textarea = data.newRemarks;
				this.remarksData.userInfo = data
			},
			//打开简历模板
			openResume(data) {
				console.log(data);
				this.remuseData.showDialog = true;
				this.$telAxios.post('/v1/librarian/selectFlexibileResumeList', {
					librarianId: data.librarianId
				}).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						this.remuseData.list = res.data.data;
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
			},
			//上传完简历之后更新视图
			updateView(msg) {
				this.uploadData.showDialog = false;
				let params = {
					librarianId: this.uploadData.userInfo.librarianId,
					changedFront: '上传一条简历',
					changedQueen: '上传的简历名为：' + msg,
					grade: '8'
				}
				this.$telAxios.post('/v1/librarian/insertDetail', params).then(res => {
					console.log(res);
					if (res.data.code === 1000) {

					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
				this.searchData(this.search.data);
			},
			//提交新增备注数据
			subRemarks(data) {
				console.log(data);
				let params = {
					librarianId: this.remarksData.userInfo.librarianId,
					changedFront: this.remarksData.userInfo.newRemarks,
					changedQueen: data,
					grade: 7,
					userId:localStorage.getItem('userid'),
					userName:localStorage.getItem('checkHuman'),
					
				}
				this.$telAxios.post('/v1/librarian/insertDetail', params).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						this.$message({
							message: '新增备注成功！',
							type: 'success'
						})
						this.$refs.remark.clearData();
						this.searchData(this.search.data);
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
				this.remarksData.showDialog = false;
			},
			//打开修改明细和备注弹窗
			openDetailsDialog(type, data) {
				console.log(type);
				console.log(data);
				this.detailsData.type = type;
				this.detailsData.userInfo = data;
				this.detailsData.showDialog = true;
				this.detailsData.title = type == '明细' ? '修改明细' : '备注';
				this.getDetailsList({
					cur: 1,
					pageSize: 10
				});
			},
			//获取明细/备注列表
			getDetailsList(obj) {
				let params = {
					librarianId: this.detailsData.userInfo.librarianId,
					pageNum: obj.cur,
					pageSize: obj.pageSize
				}
				let url = this.detailsData.type == '明细' ? '/v1/librarian/selectDetailBylibrarianId' :
					'/v1/librarian/selectPostscriptVoList';
				this.$telAxios.post(url, params).then(res => {
					console.log(res);
					if (res.data.code === 1000) {
						let result = res.data.data;
						if (this.detailsData.type == '明细') {
							result.dlist.forEach(item => {
								let mold = '修改类型：';
								if (item.grade == 1) {
									mold += '姓名';
								} else if (item.grade == 2) {
									mold += '手机号';
								} else if (item.grade == 3) {
									mold += '岗位';
								} else if (item.grade == 4) {
									mold += '工作状态';
								} else if (item.grade == 5) {
									mold += '项目归属';
								} else if (item.grade == 6) {
									mold += '标注';
								} else if (item.grade == 7) {
									mold += '备注';
								} else if (item.grade == 10) {
									mold += '性别';
								} else if (item.grade == 11) {
									mold += '年龄';
								} else if (item.grade == 12) {
									mold += '学历';
								} else if (item.grade == 13) {
									mold += '籍贯';
								} else if (item.grade == 14) {
									mold += '现住址';
								} else if (item.grade == 16) {
									mold += '面试时间';
								}else if (item.grade == 17) {
									mold += '招聘渠道';
								}else if (item.grade == 18) {
									mold += '居住地';
								}else if (item.grade == 19) {
									mold += '身份证号码';
								}else if (item.grade == 20) {
									mold += '职能';
								}else if (item.grade == 21) {
									mold += '职位';
								}else if (item.grade == 22) {
									mold += '期望薪资';
								}else if (item.grade == 23) {
									mold += '原公司城市';
								}else if (item.grade == 24) {
									mold += '原工作单位';
								}else if (item.grade == 25) {
									mold += '原年薪';
								}
								
								 if(item.grade==4){
									if(item.changedFront==1){
										item.changedFront='沟通'
									}else if(item.changedFront==2){
										item.changedFront='通知面试'
									}else if(item.changedFront==3){
										item.changedFront='实到面试'
									}else if(item.changedFront==4){
										item.changedFront='实到复试'
									}else if(item.changedFront==5){
										item.changedFront='录取'
									}else if(item.changedFront==6){
										item.changedFront='到岗'
									}else if(item.changedFront==7){
										item.changedFront='入职'
									}
									
									if(item.changedQueen==1){
										item.changedQueen='沟通'
									}else if(item.changedQueen==2){
										item.changedQueen='通知面试'
									}else if(item.changedQueen==3){
										item.changedQueen='实到面试'
									}else if(item.changedQueen==4){
										item.changedQueen='实到复试'
									}else if(item.changedQueen==5){
										item.changedQueen='录取'
									}else if(item.changedQueen==6){
										item.changedQueen='到岗'
									}else if(item.changedQueen==7){
										item.changedQueen='入职'
									}
									
								 }
								item.comment = mold + '<br/>' + ' 修改前内容：' + item.changedFront 
								if(item.changedQueen){
								item.comment+= '<br/> 修改后内容：' + item.changedQueen;	
								}
									
									
								if (item.grade == 8) {
									item.comment = '操作类型：上传一条简历' + '<br/>' + item.changedQueen;
								}
								item.comment+=`<br/><span style="color:red">修改人姓名:${item.userName}</span>`
							})
							this.detailsData.list = result.dlist;
						} else {
							this.detailsData.list = result.plist;
						}
						this.detailsData.totalNum = Number(result.totalNum);
					} else {
						this.$message({
							message: res.data.message,
							type: 'warning'
						})
					}
				})
			},
			//打开上传弹窗
			openUpload(data) {
				console.log(data);
				this.uploadData.showDialog = true;
				this.uploadData.userInfo = data;
				this.uploadData.fileList = [];
			},
			//提交数据放入回收站
			recovery(data) {
				console.log(data);
				this.$confirm('是否确认放入回收站？', '放入回收站', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning',
				}).then(() => {
					this.$telAxios.post('/v1/librarian/updateLibrarianRecycleBin', {
						librarianId: data.librarianId,
						recycleBin: 1
					}).then(res => {
						console.log(res);
						if (res.data.code === 1000) {
							this.$message({
								message: '放入回收站操作成功！',
								type: 'success'
							})
							this.searchData(this.search.data);
						} else {
							this.$message({
								message: res.data.message,
								type: 'warning'
							})
						}
					})
				}, () => {
					console.log('取消成功！');
				})
			},

			//当前页是第几页,点击的第几页的时候调用这个函数
			pageChange(p) {
				// 点击的时候传过来一个参数，这个参数就是所点击的当前页数，
				// 然后把这个当前页数转换成字符串形式赋值给page，
				// 然后把page这个参数传给search这个方法
				console.log(p);
				this.cur = p;
				this.searchData(this.search.data);
			},
			//每页有多少条,10,20,50等,点击选择的时候调用这个方法
			handleSizeChange(val) {
				console.log(val);
				this.pageSize = val;
				this.searchData(this.search.data);
			},
		}
	}
</script>

<style scoped="scoped">
	.container {
		background-color: #fff;
		height: 100%;
		padding-left: 20px;
	}

	.header-title {
		padding: 0 0 20px 0;
		border-bottom: 1px solid #D2D2D2;
	}

	.addTab /deep/ .caret-wrapper {
		display: none;
	}

	.header-title span {
		width: 15px;
		float: left;
		height: 30px;
		background-color: #0064E4;
		margin-right: 20px;
	}

	.header-title p {
		font-size: 16px;
		font-family: PingFang SC;
		line-height: 30px;
		float: left;

	}

	.pageBox {
		margin-top: 20px;
	}
</style>
